﻿using IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class MemberDAL<T> : IMemberDAL<T> where T : class
    {
        public MemberDAL(MemberDbContext context)
        {
            Context = context;
        }

        public MemberDbContext Context { get; }

        public async Task<int> AddMemberAsync(T t)
        {
            Context.Set<T>().AddAsync(t);
            return await Context.SaveChangesAsync();
        }

        public async Task<int> AddMemberRangeAsync(List<T> list)
        {
            Context.Set<T>().AddRangeAsync(list);
            return await Context.SaveChangesAsync();
        }

        public async Task<int> DeleteMemberAsync(T t)
        {
            Context.Set<T>().Remove(t);
            return await Context.SaveChangesAsync();
        }

        public async Task<int> DeleteMemberRangeAsync(List<T> list)
        {
            Context.Set<T>().RemoveRange(list);
            return await Context.SaveChangesAsync();
        }

        public IQueryable<T> GetMembersAsync()
        {
            return Context.Set<T>();
        }

        public async Task<int> UpdateMemberAsync(T t)
        {
            Context.Set<T>().Update(t);
            return await Context.SaveChangesAsync();
        }

        public async Task<int> UpdateMemberRangeAsync(List<T> list)
        {
            Context.Set<T>().UpdateRange(list);
            return await Context.SaveChangesAsync();
        }
    }
}
